package com.tanhua.dubbo.api;

import com.tanhua.domain.db.Log;
import com.tanhua.dubbo.api.db.LogApi;
import com.tanhua.dubbo.mapper.LogMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

//import static com.sun.tools.doclint.Entity.and;

@Service
public class LogApiImpl implements LogApi {
    @Autowired
    private LogMapper logMapper;

    @Override
    public void save(Log log) {
        logMapper.insert(log);
    }

 /*
    2、num_registered 有多少人注册

    select count( distinct user_id) as num from tb_log  where log_time='2021-07-10' and type='0102'

3、num_login 有多少人登录
    select count( distinct user_id) as num from tb_log  where log_time='2021-07-10' and type='0101'

4、num_active 有多少人活跃
    select count( distinct user_id) as num from tb_log  where log_time='2021-07-10'

            5、num_retention1d 当前有多少留存人数
    前一天注册后 100，今天依然在app上活跃 200

    假如今天是2021年7月10号
    select   count(distinct user_id)  as num from tb_log  where log_time='2021-07-10' and user_id in
            (select   distinct user_id  as num from tb_log  where log_time='2021-07-09' and type='0102')

*/
    @Override
    public Integer queryNumLoginOrRegistry(String todayStr, String type) {
        return logMapper.queryNumLoginOrRegistry(todayStr,type);
    }

    @Override
    public Integer queryNumActive(String todayStr) {
        return logMapper.queryNumActive(todayStr);
    }

    @Override
    public Integer queryNumRetention1d(String todayStr, String yesTodayStr) {
        return logMapper.queryNumRetention1d(todayStr,yesTodayStr);
    }
}
